package com.example.shopping.controller;

import com.example.shopping.common.consts.ResultEnum;
import com.example.shopping.common.response.RestResponse;
import com.example.shopping.pojo.domain.GoodsBean;
import com.example.shopping.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Dream
 * @version 1.0
 * @date 2020/11/9 18:44
 */
@RestController
@RequestMapping(value="goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 获取商品
     * @param value
     * @return
     */
    @RequestMapping(value="/getAll")
    public RestResponse getAll(@RequestParam(value="value",defaultValue = "") String value){
        return new RestResponse(ResultEnum.SUCCESS,goodsService.getAll(value));
    }

    /**
     * 查询商品
     * @param goodsId
     * @return
     */
    @RequestMapping(value="/getById")
    public RestResponse getById(@RequestParam(value="goodsId") Integer goodsId){
        return new RestResponse(ResultEnum.SUCCESS,goodsService.getById(goodsId));
    }

    /**
     * 添加商品
     * @param goodsBean
     * @return
     */
    @RequestMapping(value="/add")
    public void addGoods(@Validated @RequestBody GoodsBean goodsBean){
        goodsService.addGoods(goodsBean);
    }

}
